package com.cash.loan.modular.cash.controller;

import com.cash.loan.common.result.ServerResponse;
import com.cash.loan.modular.cash.service.RecommendService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.Map;

/**
 * @author Administrator
 * @description
 * @date 2018年10月02 18:38
 */
@RestController
@RequestMapping(value = "/recommend")
@Api(description = "推荐刷新")
public class RecommendController {

    private static final Logger log = LoggerFactory.getLogger(RecommendController.class);

    @Autowired
    private RecommendService recommendService;

    @ApiOperation("推荐刷新")
    @GetMapping(value = "/refresh")
    public ServerResponse getRandomNext(@RequestParam(value = "id") Integer id) {
        Map<String,Object> result = recommendService.refresh(id);
        return ServerResponse.getSuccess("success",result);
    }

    @ApiOperation("根据推荐位编号获取推荐位信息")
    @GetMapping(value = "/{num}")
    public ServerResponse getRecommendByFieldNum(@PathVariable(value="num") Integer num) {
        if(num <= 0) {
            return ServerResponse.getErrorMessage("推荐位索引错误");
        }
        Map<String,Object> result = recommendService.getRecommendByNum(num);
        return ServerResponse.getSuccess("success",result);
    }
}
